﻿@model List<Article>

<div class="container">

    <h1 class="display-4">Blog</h1>
    <br />
    <a asp-action="Upload" class="btn btn-primary">Upload Blog</a>
    <br /><br />

    <div class="overflow-auto">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th scope="col">ArticleCode</th>
                    <th scope="col">ArticleTitle</th>
                    <th scope="col">Modify</th>
                    <th scope="col">Comment</th>
                    <th scope="col">Delete</th>
                </tr>
            </thead>

            <tbody>
                @foreach (var article in Model)
                {
                    <tr>
                        <th scope="row">@article.ArticleCode.ToString().Substring(0, 6)</th>
                        <td>@article.Title</td>
                        <td><a asp-action="Modify" asp-route-id="@article.ArticleCode" class="badge badge-warning">Modify</a></td>
                        <td><a asp-action="Comment" asp-route-id="@article.ArticleCode" class="badge badge-info">Comment</a></td>
                        <td>
                            @{
                                var formLink = new FormLink()
                                {
                                    Href = "/Admin/Blog/Delete/",
                                    Text = "Delete",
                                    ClassName = "badge badge-danger",
                                    Warning = "Confirm deletion?"
                                };
                                formLink.Paras.Add("id", article.ArticleCode.ToString());
                            }
                            @await Component.InvokeAsync("FormLink", formLink)
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>

    <nav class="mt-4">
        @{
            string previous = "", next = "";
            if (ViewBag.CurrentIndex <= 1)
                previous = "disabled";
            if (ViewBag.CurrentIndex >= ViewBag.PageCount)
                next = "disabled";
        }
        <ul class="pagination justify-content-center">
            <li class="page-item">
                <button @previous class="page-link" onclick="window.location.href='/Admin/Blog?index=@(ViewBag.CurrentIndex-1)'">&lt;</button>
            </li>
            <li class="page-item">
                <button class="page-link" disabled>Page @ViewBag.CurrentIndex of @ViewBag.PageCount</button>
            </li>
            <li class="page-item">
                <button @next class="page-link" onclick="window.location.href='/Admin/Blog?index=@(ViewBag.CurrentIndex+1)'">&gt;</button>
            </li>
        </ul>
    </nav>

</div>
